<template>
  <div class="admin-dashboard">
    <el-container class="dashboard-container">
      <el-aside width="200px" class="aside">
        <div class="logo">
          <h2>医院管理系统</h2>
        </div>
        <el-menu
          class="menu"
          router
          :default-active="activeMenu"
          background-color="#304156"
          text-color="#bfcbd9"
          active-text-color="#409EFF">
          <el-menu-item index="/admin">
            <el-icon><HomeFilled /></el-icon>
            <span>首页</span>
          </el-menu-item>
          <el-menu-item index="/admin/users">
            <el-icon><UserFilled /></el-icon>
            <span>患者管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/doctors">
            <el-icon><User /></el-icon>
            <span>医生管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/drugs">
            <el-icon><Film /></el-icon>
            <span>药品管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/checks">
            <el-icon><List /></el-icon>
            <span>检查项目管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/schedule">
            <el-icon><Calendar /></el-icon>
            <span>医生排班管理</span>
          </el-menu-item>
          <el-menu-item index="/admin/visualization">
            <el-icon><DataLine /></el-icon>
            <span>数据可视化</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      
      <el-container>
        <el-header class="header">
          <div class="left"></div>
          <div class="right">
            <el-dropdown trigger="click">
              <span class="user-info">
                {{ user?.name || 'Admin' }}
                <el-icon><CaretBottom /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item @click="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </el-header>
        
        <el-main class="main">
          <router-view v-if="$route.path !== '/admin'" />
          <admin-home v-else />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useAuthStore } from '../../stores/auth'
import { 
  HomeFilled, 
  UserFilled, 
  User, 
  Film, 
  List, 
  Calendar, 
  DataLine, 
  CaretBottom 
} from '@element-plus/icons-vue'
import AdminHome from './Home.vue'

const authStore = useAuthStore()
const route = useRoute()
const router = useRouter()

const user = computed(() => authStore.user)
const activeMenu = computed(() => route.path)

const logout = () => {
  authStore.logout()
}

onMounted(() => {
  if (!authStore.isAuthenticated || authStore.userRole !== 'admin') {
    router.push('/login')
  }
})
</script>

<style scoped>
.admin-dashboard {
  height: 100vh;
  overflow: hidden;
}

.dashboard-container {
  height: 100%;
}

.aside {
  background-color: #304156;
  color: #fff;
  height: 100%;
  overflow-x: hidden;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background-color: #2b3649;
}

.logo h2 {
  font-size: 18px;
  margin: 0;
  white-space: nowrap;
}

.menu {
  border-right: none;
}

.header {
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #dcdfe6;
  padding: 0 20px;
  height: 60px;
}

.right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.main {
  background-color: #f5f7fa;
  height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 20px;
}
</style> 